/* Testing the village card effect, this is a card I refactored. */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set TEST_OUTPUT to 0 to remove printfs from output
#define TEST_OUTPUT 1

int main() {
	int i;
	int seed = 100;
	int numPlayer = MAX_PLAYERS;
	//These just satisfy the card effect function call, but (perceivably) have no bearing on the card under test
	int choice1 = 0;
	int choice2 = 0;
	int choice3 = 0;
	int *bonus = NULL;
	//End filler variables
	int currentPlayer;
	int handPos;
	//From the example
	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
	struct gameState G;
	struct gameState G_before;
	//Taken from the example testUpdateCoins.c, but still quite necessary.
	memset(&G, 23, sizeof(struct gameState));   			// clear the game state
    initializeGame(numPlayer, k, seed, &G); 			// initialize a new game
	memcpy(&G_before, &G, sizeof(struct gameState));		//Copy the initialized game state for future reference and state adjustment.
	//Set up the hand and player
	currentPlayer = 0;
	handPos = 0;
	//Insert the card in player 0's hand in position 0
	G.hand[currentPlayer][handPos] = village;
	//Now play the card and make sure all the expected state changes have occurred
	i = cardEffect(village, choice1, choice2, choice3, &G, handPos, bonus);
	
	//The number of cards in the hand of the player should now be the same as before (+1 from card and minus 1 from the discard at the end of the function)
	if (TEST_OUTPUT) printf("G.handCount[currentPlayer] is %d\nG_before.handCount[currentPlayer] is %d\n", G.handCount[currentPlayer], G_before.handCount[currentPlayer]);
	assert(G.handCount[currentPlayer] == G_before.handCount[currentPlayer]);
	
	//The number of actions should be incremented by 1
	assert(G.numActions == (G_before.numActions + 2));
	
	//Now to make sure the played card is discarded and the handCount decremented.
	//THIS IS ALREADY ACCOUNTED FOR IN THE ABOVE HANDCOUNT CHECK. NO NEED TO REPEAT HERE
	
	//Need to check that the discarded card is added to the playedCardCount  THIS WILL FAIL AS THE THIS IS THE BUG I INSERTED IN MY REFACTORED FUNCTION.  I"M GLAD IT WORKED TO CATCH IT.
	if (TEST_OUTPUT) printf("G.playedCardCount is %d\nG_before.playedCardCount is %d\nTHIS WILL FAIL AS THE THIS IS THE BUG I INSERTED IN MY REFACTORED FUNCTION\n", G.playedCardCount, G_before.playedCardCount);
	//assert(G.playedCardCount == (G_before.playedCardCount + 1));   //Have to comment it out to make the makefile automated testing to work.
	
	//Finally make sure card effect returns the correct value
	assert(i == 0);
	
	printf("Cardtest4: All Tests Passed!\n");
	return 0;
}